<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
        <script src="../js/healthmobile.js"></script>
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>预约管理<small>预约列表</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>预约管理</el-breadcrumb-item>
                    <el-breadcrumb-item>预约列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="档案/姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="findPageByPageString()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                        <div style="float:right;margin-right: 100px"><el-button size="primary" type="danger" @click="handleBatchCancel()">批量取消预约</el-button></div>
                    </div>
                    <el-table  size="small" current-row-key="id" :data="dataList" stripe highlight-current-row  @selection-change="handleSelectionChange">

                        <el-table-column type="selection" align="center"></el-table-column>
                        <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                        <el-table-column prop="member.fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column prop="member.name" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="member.phoneNumber" label="手机号码" sortable align="center"></el-table-column>
                        <el-table-column prop="orderType" label="预约类型" sortable align="center"></el-table-column>
                        <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                        <el-table-column label="操作" align="center" width="300" >
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleConfirm(scope.row)">确认预约</el-button>
                                <el-button size="mini" type="danger" @click="handleCancel(scope.row)">取消预约</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                            <template>
                                <el-tabs v-model="activeName" type="card">
                                    <el-tab-pane label="基本信息" name="first">
                                        <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="姓名" prop="name">
                                                        <el-input v-model="formData.name"/>
                                                    </el-form-item>
                                                </el-col>
                                                <el-col :span="12">
                                                    <el-form-item label="手机号" prop="phoneNumber">
                                                        <el-input v-model="formData.phoneNumber"/>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                            <el-row>
                                                <el-col :span="12">
                                                    <el-form-item label="预约日期" prop="orderDate">
                                                        <el-date-picker
                                                                v-model="value"
                                                                type="datetime"
                                                                placeholder="选择日期时间"
                                                                value-format="yyyy-MM-dd">
                                                        </el-date-picker>
                                                    </el-form-item>
                                                </el-col>
                                            </el-row>
                                        </el-form>
                                    </el-tab-pane>
                                    <el-tab-pane label="预约套餐" name="second">
                                        <div class="checkScrol">
                                            <table class="datatable">
                                                <thead>
                                                <tr>
                                                    <th>选择</th>
                                                    <th>套餐编码</th>
                                                    <th>套餐名称</th>
                                                    <th>套餐说明</th>
                                                </tr>
                                                </thead>
                                                <tbody>
                                                <tr v-for="c in tableData">
                                                    <td>
                                                        <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                                    </td>
                                                    <td><label :for="c.id">{{c.code}}</label></td>
                                                    <td><label :for="c.id">{{c.name}}</label></td>
                                                    <td><label :for="c.id">{{c.remark}}</label></td>
                                                </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </el-tab-pane>
                                </el-tabs>
                            </template>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                activeName:'first',//添加窗口Tab标签名称
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:0,//总记录数
					  queryString:null//查询条件
				},
				dataList: [{name:"male"}],//当前页要展示的分页列表数据
                formData: {
                    orderType:'电话预约',
                },//表单数据
                tableData:[],//新增表单中对应的套餐列表数据
                setmealIds:[],//新增表单中套餐对应的复选框，基于双向绑定可以进行回显和数据提交
                dialogFormVisible: false,//增加表单是否可见
                rules: {//校验规则
                    phoneNumber: [{ required: true, message: '手机号码为必填项', trigger: 'blur' }],
                    name: [{ required: true, message: '姓名为必填项', trigger: 'blur' }]
                },
                value: '',
                multipleSelection:'' // 预约列表复选框
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {

                this.findPage();
            },
            methods: {
                 showMessage(r) {
                     console.log(r);
                     // if (r == 'Error: Request failed with status code 403') {
                     if (r == 'Error: Request failed with status code 403') {
                         this.$message.error('无访问权限');
                         return;
                     } else {
                         this.$message.error('未知错误');
                         return;
                     }
                 },

                //添加
                handleAdd () {

                    // 校验telephone
                    var telephone = this.formData.phoneNumber;
                    if (!checkTelephone(telephone)) {
                        this.$message.error("请输入正确的手机号");
                        return false;
                    }

                     var param = {
                        orderType: this.formData.orderType,
                        name: this.formData.name,
                        phoneNumber: this.formData.phoneNumber,
                        orderDate:this.value
                    };

                    // 校验是否选择套餐
                    if (this.setmealIds ==null || this.setmealIds.length == 0){
                        this.$message.error("请选择预约套餐");
                        return false;
                    }

                    // 校验是否选择日期
                    var orderDate = param.orderDate;
                    if (orderDate == null || orderDate.length == 0){
                        this.$message.error("请选择预约日期");
                        return false;
                    }

                    axios.post("/ordersettinglist/add.do?setmealIds="+this.setmealIds,param).then((res) =>{
                        if (res.data.flag){
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            this.pagination.currentPage = "1";
                            this.findPage();
                        } else {
                            this.$message.error(res.data.message);
                        }

                    }).finally(() =>{
                        // 隐藏添加窗口
                        this.dialogFormVisible = false;
                    })
                },
                //分页查询
                findPage() {
                    var param = {
                        currentPage: this.pagination.currentPage,
                        pageSize: this.pagination.pageSize,
                        queryString: this.pagination.queryString
                    };

                    axios.post("/ordersettinglist/findPage.do",param).then((res) => {
                        this.dataList = res.data.rows;
                        this.pagination.total = res.data.total;
                    })
                },
                // 根据条件查询
                findPageByPageString(){
                    this.pagination.currentPage = "1";
                    this.findPage();
                },
                // 重置表单
                resetForm() {
                    this.formData = {
                        orderType:'电话预约',
                        orderStatus:'已预约'
                    };
                    this.value = '';
                },
                // 弹出添加窗口
                handleCreate() {
                    this. dialogFormVisible = true;
                    this.resetForm();
                    this.activeName = "first";
                    this.setmealIds = [];
                    // 查询套餐数据
                    axios.post("/setmeal/findAll.do").then((res) =>{
                        this.tableData = res.data.data;
                    })
                },

                //切换页码
                handleCurrentChange(currentPage) {
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                
                //确认预约
                handleConfirm(row) {

                    this.$confirm('此操作将确认预约, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        axios.get("/ordersettinglist/confirm.do?telephone="+row.member.phoneNumber).then((res) =>{
                            if (res.data.flag){
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message);
                            }
                        })

                    }).catch(() => {
                        this.$message({
                            message: "操作已取消",
                            type: 'info'
                        });
                    });


                },

                // 取消预约
                handleCancel(row) {


                    this.$confirm('此操作将取消预约, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        var param = {
                            id:row.id,
                            telephone:row.member.phoneNumber,
                        };
                        axios.post("/ordersettinglist/cancel.do",param).then((res) =>{
                            if (res.data.flag){
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message);
                            }
                        })

                    }).catch(() => {
                        this.$message({
                            message: "操作已取消",
                            type: 'info'
                        });
                    });

                },

                //批量取消预约
                handleBatchCancel(){
                    var value = this.multipleSelection;
                    var orderIds = new Array();
                    for (let i = 0; i < value.length; i++) {
                        orderIds.push(value[i].id)
                    }

                    this.$confirm('此操作将批量取消预约, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        // 校验是否选择列表复选框
                        if (orderIds ==null || orderIds.length == 0){
                            this.$message.error("请选择要取消的预约");
                            return false;
                        }

                        axios.post("/ordersettinglist/batchCancel.do?orderIds="+orderIds).then((res) =>{
                            if (res.data.flag){
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                this.findPage();
                            } else {
                                this.$message.error(res.data.message);
                            }
                        })

                    }).catch(() => {
                        this.$message({
                            message: "操作已取消",
                            type: 'info'
                        });
                    });


                },
                //
                handleSelectionChange(val) {
                    this.multipleSelection = val;
                }
            }
        })
    </script>
</html>